﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Web;

namespace Pcb.Common
{
    /// <summary>
    /// 操作Session
    /// </summary>
    /// <param name="strKey">key</param>
    /// <param name="objValue">要保存的值</param>
    /// <returns></returns>
    public class _Session
    {
        /// <summary>
        /// 保存 Session 值
        /// </summary>   
        public static bool SetSession(string strKey, string strValue)
        {
            try
            {
                HttpContext.Current.Session[strKey] = strValue;                
                return true;
            }
            catch
            {
            }
            return false;
        }

        /// <summary>
        /// 保存Session值
        /// </summary>
        /// <param name="strKey">key</param>
        /// <param name="objValue">要保存的值</param>
        /// <returns></returns>
        public static bool SetSession(string strKey, Object objValue)
        {
            try
            {
                HttpContext.Current.Session[strKey] = objValue;                
                return true;
            }
            catch
            {
            }
            return false;
        }

        /// <summary>
        /// 获取 Session 值
        /// </summary>
        /// <param name="strName"> session名 </param>
        /// <returns></returns>
        public static string GetSession(string strName)
        {
            Object session = HttpContext.Current.Session[strName];
            if (session != null)
            {
                return session.ToString();
            }
            return "";
        }

        /// <summary>
        /// 获取 Session 值
        /// </summary>
        /// <param name="strName"> session名 </param>
        /// <returns></returns>
        public static Object GetSessionObject(string strName)
        {
            Object session = HttpContext.Current.Session[strName];
            if (session != null)
            {
                return session;
            }
            return null;
        }

        /// <summary>
        /// 删除 Session 值
        /// </summary>
        /// <param name="strName"> session名 </param>
        /// <returns></returns>
        public static bool DelSession(string strName)
        {
            try
            {
                HttpContext.Current.Session.Remove(strName);
            }
            catch
            {
            }
            return false;
        }

    }
}
